/*
 * @Description: 
 * @Author: wind-lc
 * @version: 1.0
 * @Date: 2022-02-28 09:21:59
 * @LastEditTime: 2023-02-14 15:50:20
 * @FilePath: \cscec-pms-admin\src\views\project\projectManagementPlanning\projectManagementPlanningComponents\mixins.js
 */
//  动态组件的逻辑全部在这里处理
export default {
    data() {
        return {
            componentName: this.$route.query?.pageName || '',
            componentPageType: this.$route.query?.pageType || ''
        }
    },
    computed: {
    },
    watch: {
        componentName: {
            handler(val) {
                console.log(val)
                if (val) {
                    if (this.componentPageType === 'detail') {   //详情置灰
                        this.addConfig(true)
                    } else {
                        this.addConfig(false)
                    }
                }
            },
            immediate: true
        },
    },
    methods: {
        // 处理特殊的表单和验证
        addConfig(flag) {
            const component = {
                constructionSiteSurvey: {
                    formItems: [
                        {
                            label: '项目地址',
                            keyName: 'projectAddress',
                            type: 'BaseInput',
                            span: 24,
                        }
                    ],
                    rules: {
                        projectAddress: [{ required: true, message: '请选择项目地址', trigger: 'change' }]
                    }
                },
            }
            if (flag) {
                let formItems = component[this.componentName]?.formItems || [];
                if (formItems.length) {
                    formItems.map((item) => {
                        item.disabled = true;
                    })
                }
            }
            if (component[this.componentName]) {
                const { formItems, rules } = component[this.componentName]
                formItems && this.formOption.push(...formItems)
                rules && Object.assign(this.rules, rules)
            }
        },
        /**
         * @description 通知组件提交
         * 提交： 组件提交定义为 组件名+Submit
         * 草稿： 组件提交定义为 组件名+SaveDrafts
         */
        emitComponentSubmit(type) {
            this.$refs.component[`${this.componentName}${type}`](this.form)

        }
    }
}